<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    :cancelText="$t('关闭')"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel" v-if="!disabled">{{ $t('取消') }}</a-button>
      <a-button @click="handleOk" type="primary" v-if="!disabled">{{ $t('保存') }}</a-button>
      <a-button @click="handleCancel" v-if="disabled">{{ $t('关闭') }}</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <div>
        <a-form-model :rules="rules" :model="model" ref="form">
          <a-row>
            <a-col :span="24">
              <a-form-model-item :label="$t('名称')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
                <a-input v-model="model.name" :disabled="disabled"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item :label="$t('状态')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
                <a-select v-model="model.state" :disabled="disabled">
                  <a-select-option v-for="(item, index) in stateList" :value="item.value" :key="index">{{
                    item.title
                  }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                :label="$t('有效期')"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                required
                style="margin-bottom: 0"
              >
                <a-row>
                  <a-col :span="10">
                    <a-form-model-item prop="beginTime">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                        :placeholder="$t('请选择开始日期')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.beginTime"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="1" style="text-align: center"
                    ><span>~</span></a-col
                  >
                  <a-col :span="10">
                    <a-form-model-item prop="endTime">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                        :placeholder="$t('请选择结束日期')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.endTime"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="3">
                    <a-button type="primary" @click="setLongTime">{{ $t('不限期') }}</a-button>
                  </a-col>
                </a-row>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '0'">
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('有效日')" required>
                <a-checkbox-group v-model="model.weeks" style="margin-top: 6px; margin-left: 5px" :disabled="disabled">
                  <a-checkbox style="margin-left: 8px" :value="item.key" v-for="item in weeks" :key="item.key">{{
                    item.name
                  }}</a-checkbox>
                </a-checkbox-group>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '0'">
              <a-form-model-item :label="$t('有效时段')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <template v-for="(vTime, index) in periodList">
                  <a-tag :key="index" closable @close="delValidTime(index)" class="tag-active">
                    {{ vTime.beginTime + '~' + vTime.endTime }}
                  </a-tag>
                </template>
                <a-button type="link" @click="addValidTime" v-if="!isAdd">{{ $t('添加') }}</a-button>
                <span v-else style="padding-left: 6px">
                  <a-time-picker
                    v-model="beginTime"
                    :placeholder="$t('开始时间')"
                    format="HH:mm"
                    style="width: 120px"
                    @openChange="focusTimeE"
                  />~
                  <a-time-picker
                    v-model="endTime"
                    :placeholder="$t('结束时间')"
                    format="HH:mm"
                    style="width: 120px"
                    @openChange="orgTime"
                  />
                </span>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '0'">
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('排除日期')">
                <div>
                  <div v-for="(time, i) in excludeTimeList" :key="i">
                    <j-date
                      date-format="YYYY-MM-DD"
                      :placeholder="$t('请选择开始日期')"
                      v-model="time.beginTime"
                      :disabled="time.disabled"
                    ></j-date
                    >~
                    <j-date
                      date-format="YYYY-MM-DD"
                      :placeholder="$t('请选择结束日期')"
                      v-model="time.endTime"
                      :disabled="time.disabled"
                    ></j-date>
                    <span v-if="!disabled">
                      <span>
                        <a-icon
                          v-if="time.disabled"
                          @click="editTime(time)"
                          type="edit"
                          style="color: #1890ff; cursor: pointer; margin-left: 5px"
                        />
                        <a-icon
                          v-else
                          type="check"
                          @click="saveTime(time)"
                          style="color: #1890ff; cursor: pointer; margin-left: 5px"
                        />
                      </span>
                      <a-icon
                        type="close"
                        @click="delTime(time)"
                        style="color: #1890ff; cursor: pointer; margin-left: 5px"
                      />
                      <a-icon
                        type="plus"
                        v-if="i == excludeTimeList.length - 1"
                        @click="addTime()"
                        style="color: #1890ff; cursor: pointer; margin-left: 5px"
                      />
                    </span>
                  </div>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '5'">
              <a-form-model-item
                :label="$t('付定金时间')"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                required
                style="margin-bottom: 0"
              >
                <a-row>
                  <a-col :span="10">
                    <a-form-model-item prop="depositBegin">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                        :placeholder="$t('请选择开始时间')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.depositBegin"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="1" style="text-align: center"
                    ><span>~</span></a-col
                  >
                  <a-col :span="10">
                    <a-form-model-item prop="depositEnd">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                        :placeholder="$t('请选择结束时间')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.depositEnd"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '5'">
              <a-form-model-item
                :label="$t('付尾款时间')"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                required
                style="margin-bottom: 0"
              >
                <a-row>
                  <a-col :span="10">
                    <a-form-model-item prop="finalBegin">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                        :placeholder="$t('请选择开始时间')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.finalBegin"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="1" style="text-align: center"
                    ><span>~</span></a-col
                  >
                  <a-col :span="10">
                    <a-form-model-item prop="finalEnd">
                      <a-date-picker
                        :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                        :placeholder="$t('请选择结束时间')"
                        :disabled="disabled"
                        valueFormat="YYYY-MM-DD HH:mm:ss"
                        v-model="model.finalEnd"
                        style="width: 100%"
                      />
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '5'">
              <a-form-model-item
                :label="$t('会员限购')"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                prop="memberLimit"
              >
                <a-input v-model="model.memberLimit" :disabled="disabled"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item :label="$t('简介')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-textarea v-model="model.intro" :row="2" :disabled="disabled"></a-textarea>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '0'">
              <a-form-model-item :label="$t('商品折扣')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-button type="primary" @click="addDiscount" v-if="!disabled">{{ $t('新增') }}</a-button>
                <a-table
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="columns"
                  :dataSource="dataSource"
                  :pagination="false"
                  :loading="false"
                  class="j-table-force-nowrap"
                  style="margin-top: 7px"
                >
                  <span slot="action" slot-scope="text, record">
                    <a @click="delKind(record)" v-if="!disabled">{{ $t('删除') }}</a>
                  </span>
                </a-table>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '1'">
              <a-form-model-item :label="$t('满减规则')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <div v-for="(item, index) in ruleList" :key="index">
                  {{ $t('满')
                  }}<a-input
                    v-model="item.full"
                    style="width: 100px; margin: 0 5px"
                    :disabled="item.disabled"
                  ></a-input>
                  {{ $t('减')
                  }}<a-input
                    v-model="item.discount"
                    style="width: 100px; margin: 0 7px"
                    :disabled="item.disabled"
                  ></a-input>
                  <span v-if="!disabled">
                    <span>
                      <a-icon
                        v-if="item.disabled"
                        @click="editRule(item)"
                        type="edit"
                        style="color: #1890ff; cursor: pointer; margin-left: 5px"
                      />
                      <a-icon
                        v-else
                        type="check"
                        @click="saveRule(item)"
                        style="color: #1890ff; cursor: pointer; margin-left: 5px"
                      />
                    </span>
                    <a-icon
                      type="close"
                      @click="delRule(item)"
                      style="color: #1890ff; cursor: pointer; margin-left: 5px"
                    />
                    <a-icon
                      type="plus"
                      v-if="index == ruleList.length - 1"
                      @click="addRule()"
                      style="color: #1890ff; cursor: pointer; margin-left: 5px"
                    />
                  </span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '1'">
              <a-form-model-item
                :label="$t('适用商品分类')"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                style="margin-bottom: 5px; margin-left: 4px"
              >
                <div>
                  <div style="display: inline-block" v-for="(item, index, key) in goodSortList" :key="key">
                    {{ item.kindName }}
                    <a-icon
                      @click="delDelGoods(item, index, 'exclude')"
                      style="color: #1890ff; cursor: pointer"
                      type="close"
                      :disabled="disabled"
                      v-if="!disabled"
                    />，
                  </div>
                  <span>
                    <a href="javascript:void(0);" @click="addGoods()" style="margin-left: 5px" v-if="!disabled"
                      >+{{ $t('添加') }}</a
                    >
                  </span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '2'">
              <a-form-model-item
                :label="$t('秒杀商品')"
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
              >
                <a-button type="primary" @click="addSeckill" v-if="!disabled">{{ $t('新增') }}</a-button>
                <a-table
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="secColumns"
                  :dataSource="secDataSource"
                  :pagination="false"
                  :loading="false"
                  class="j-table-force-nowrap"
                  style="margin-top: 7px"
                >
                  <span slot="action" slot-scope="text, record">
                    <a @click="delSeckill(record)" v-if="!disabled">{{ $t('删除') }}</a>
                  </span>
                  <template v-for="col in ['sort']" :slot="col" slot-scope="text, record">
                    <div :key="col" style="display: flex; justify-content: center">
                      <div>
                        <a-input
                          v-if="record.editable"
                          style="margin: -5px 0; padding: 0; width: 50px"
                          :value="text"
                          @change="(e) => handleChange(e.target.value, record.goodsId, col)"
                          :maxLength="3"
                        />
                        <template v-else>{{ text }}</template>
                      </div>
                      <div class="editable-row-operations" v-if="!disabled">
                        <span v-if="record.editable">
                          <a @click="() => saveSeckill(record.goodsId)"><a-icon type="save" /></a>
                        </span>
                        <span v-else>
                          <a @click="() => editSeckill(record.goodsId)"><a-icon type="edit" /></a>
                        </span>
                      </div>
                    </div>
                  </template>
                </a-table>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '3'">
              <a-form-model-item
                :label="$t('奖品设置')"
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
                required
              >
                <a-table
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="cjColumns"
                  :dataSource="cjDataSource"
                  :pagination="false"
                  :loading="false"
                  class="j-table-force-nowrap"
                  style="margin-top: 7px"
                >
                  <template slot="goodsForm" slot-scope="text, record, ind">
                    <j-dict-select-tag
                      v-model="record.goodsForm"
                      dictCode="bis_activity_draw_goods.goods_form"
                      style="width: 140px"
                      :placeholder="$t('请选择')"
                      :isdefShow="false"
                      @change="(e) => changeForm(e, ind)"
                    />
                  </template>
                  <template slot="goodsId" slot-scope="text, record, ind">
                    <a-select
                      show-search
                      v-model="record.goodsId"
                      style="width: 200px"
                      :placeholder="$t('请选择')"
                      :disabled="record.goodsForm == 0"
                      :filterOption="false"
                      @change="hangeleChange"
                      @search="(e) => handleSearch(e, ind)"
                    >
                      <a-select-option v-for="(item, i) in record.goodsList" :key="i" :value="item.id">
                        {{ item.name }}
                      </a-select-option>
                    </a-select>
                  </template>
                  <template slot="shortName" slot-scope="text, record">
                    <a-input v-model="record.shortName" :disabled="record.goodsForm == 0"></a-input>
                  </template>
                  <template slot="amount" slot-scope="text, record">
                    <a-input v-model="record.amount" oninput="value=value.replace(/\D/g,'')"></a-input>
                  </template>
                </a-table>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '3'">
              <a-form-model-item
                :label="$t('抽奖方式')"
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
                required
              >
                <div>
                  <i18n path="free-cj" tag="div">
                    <a-checkbox place="cjtype" v-model="isFree" style="margin-right: 14px">{{
                      $t('免费抽奖')
                    }}</a-checkbox>
                    <a-input
                      place="num"
                      v-model="freeNum"
                      oninput="value=value.replace(/\D/g,'')"
                      style="width: 80px"
                    ></a-input>
                  </i18n>
                  <i18n path="consume-cj" tag="div">
                    <a-checkbox place="cjtype" v-model="isConsume" style="margin-right: 14px">{{
                      $t('消费抽奖')
                    }}</a-checkbox>
                    <a-input
                      place="value"
                      v-model="consumeValue"
                      oninput="value=value.replace(/\D/g,'')"
                      style="width: 100px; margin: 0 4px"
                    ></a-input>
                    <a-input
                      place="num"
                      v-model="consumeNum"
                      oninput="value=value.replace(/\D/g,'')"
                      style="width: 80px; margin: 0 4px"
                    ></a-input>
                  </i18n>
                  <i18n path="deposit-cj" tag="div">
                    <a-checkbox place="cjtype" v-model="isDeposit" style="margin-right: 14px">{{
                      $t('存票抽奖')
                    }}</a-checkbox>
                    <a-input
                      place="value"
                      v-model="depositValue"
                      oninput="value=value.replace(/\D/g,'')"
                      style="width: 100px; margin: 0 4px"
                    ></a-input>
                    <a-input
                      place="num"
                      v-model="depositNum"
                      oninput="value=value.replace(/\D/g,'')"
                      style="width: 80px; margin: 0 4px"
                    ></a-input>
                  </i18n>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '4'">
              <a-form-model-item :label="$t('升单规则')" :labelCol="labelCol" :wrapperCol="wrapperCol1">
                <div v-for="(item, index) in upgradeOrdersList" :key="index">
                  <span style="padding-right: 4px">{{ $t('原套餐') }}</span>
                  <a-select
                    v-model="item.originalGoodsId"
                    style="width: 200px; margin-right: 4px"
                    @change="(val) => changeRecharge(val, index)"
                  >
                    <a-select-option v-for="(ele, i) in recharges" :key="i" :value="ele.id">{{
                      ele.name
                    }}</a-select-option>
                  </a-select>
                  <span style="padding-right: 4px">{{ $t('推荐套餐') }}</span>
                  <a-select
                    v-model="item.recommendedGoodsId"
                    style="width: 200px; margin-right: 4px"
                    :disabled="item.disabled"
                  >
                    <a-select-option v-for="(ele, i) in item.recharges" :key="i" :value="ele.id">{{
                      ele.name
                    }}</a-select-option>
                  </a-select>
                  <span v-if="!disabled">
                    <a-icon
                      type="close"
                      @click="delRecharge(item)"
                      style="color: #1890ff; cursor: pointer; margin-left: 5px"
                    />
                    <a-icon
                      type="plus"
                      v-if="index == upgradeOrdersList.length - 1"
                      @click="addRecharge"
                      style="color: #1890ff; cursor: pointer; margin-left: 5px"
                    />
                  </span>
                </div>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" v-if="acvivityType == '5'">
              <a-form-model-item
                :label="$t('预售商品')"
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
              >
                <a-button type="primary" @click="addPresale" v-if="!disabled">{{ $t('新增') }}</a-button>
                <a-table
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="psColumns"
                  :dataSource="psDataSource"
                  :pagination="false"
                  :loading="false"
                  class="j-table-force-nowrap"
                  style="margin-top: 7px"
                >
                  <span slot="action" slot-scope="text, record">
                    <a @click="delPresale(record)" v-if="!disabled">{{ $t('删除') }}</a>
                  </span>
                  <template v-for="col in ['sort']" :slot="col" slot-scope="text, record">
                    <div :key="col" style="display: flex; justify-content: center">
                      <div>
                        <a-input
                          v-if="record.editable"
                          style="margin: -5px 0; padding: 0; width: 50px"
                          :value="text"
                          @change="(e) => handleChangePs(e.target.value, record.goodsId, col)"
                          :maxLength="3"
                        />
                        <template v-else>{{ text }}</template>
                      </div>
                      <div class="editable-row-operations" v-if="!disabled">
                        <span v-if="record.editable">
                          <a @click="() => savePresale(record.goodsId)"><a-icon type="save" /></a>
                        </span>
                        <span v-else>
                          <a @click="() => editPresale(record.goodsId)"><a-icon type="edit" /></a>
                        </span>
                      </div>
                    </div>
                  </template>
                </a-table>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <a-modal
        :title="$t('新增')"
        :visible="discountVisible"
        :destroyOnClose="false"
        :okText="$t('确定')"
        :cancelText="$t('取消')"
        :width="700"
        @ok="handleOkDiscount"
        @cancel="handleClose"
      >
        <a-form-model :model="dis" :rules="disrules" ref="disform">
          <a-row>
            <a-col :span="24">
              <a-form-model-item :label="$t('商品分类')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-tree-select
                  style="width: 100%"
                  :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
                  :tree-data="treeData"
                  :search-placeholder="$t('请选择')"
                  v-model="dis.kindId"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item :label="$t('商品折扣')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discount">
                <a-input v-model="dis.discount" style="width: 95%" :placeholder="$t('请输入1~100之间的整数')"></a-input>
                %
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-modal>
    </a-spin>
    <add-kind-modal ref="kindForm" @ok="addKindCallback"></add-kind-modal>
    <add-seckill-goods-modal ref="seckillForm" @ok="addSeckillGoods"></add-seckill-goods-modal>
    <add-presale-goods-modal ref="presaleForm" @ok="addPresaleGoods"></add-presale-goods-modal>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { getAction, httpAction } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import AddKindModal from './AddKindModal'
import AddSeckillGoodsModal from './AddSeckillGoodsModal'
import AddPresaleGoodsModal from './AddPresaleGoodsModal'

export default {
  name: 'AddActivityDetailModal',
  components: { AddKindModal, AddSeckillGoodsModal, AddPresaleGoodsModal },
  data() {
    return {
      moment,
      width: 800,
      visible: false,
      model: {
        state: 1,
        weeks: ['1', '2', '3', '4', '5', '6', '7'],
      },
      dis: {
        kindId: '',
        discount: undefined,
      },
      confirmLoading: false,
      title: '',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 17 },
      },
      wrapperCol1: {
        xs: { span: 24 },
        sm: { span: 20 },
      },
      columns: [
        {
          title: this.$t('商品分类'),
          align: 'center',
          dataIndex: 'kindName',
        },
        {
          title: this.$t('折扣'),
          align: 'center',
          dataIndex: 'discount',
          customRender: (text, record) => {
            return text + '%'
          },
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      dataSource: [],
      rules: {
        name: [{ required: true, message: this.$t('请设置活动名称') }],
        state: [{ required: true, message: this.$t('请选择状态') }],
        beginTime: [{ required: true, message: this.$t('请选择开始日期') }],
        endTime: [{ required: true, message: this.$t('请选择结束日期') }],
        depositBegin: [{ required: true, message: this.$t('请选择开始时间') }],
        depositEnd: [{ required: true, message: this.$t('请选择结束时间') }],
        finalBegin: [{ required: true, message: this.$t('请选择开始时间') }],
        finalEnd: [{ required: true, message: this.$t('请选择结束时间') }],
        memberLimit: [{ required: true, message: this.$t('请输入会员限购数量') }],
      },
      disrules: {
        discount: [{ required: true, message: this.$t('请输入1~100之间的整数'), pattern: /^([1-9][0-9]{0,1}|100)$/ }],
      },
      //弹框
      treeData: [],
      discountVisible: false,
      stateList: [],

      disabled: false,
      acvivityType: '',
      ruleList: [],
      goodSortList: [],

      secColumns: [
        {
          title: this.$t('排序序号'),
          dataIndex: 'sort',
          align: 'center',
          scopedSlots: { customRender: 'sort' },
          customCell: () => {
            return {
              style: {
                width: '80px',
              },
            }
          },
        },
        {
          title: this.$t('商品'),
          align: 'center',
          dataIndex: 'goodsName',
        },
        {
          title: this.$t('售价'),
          align: 'center',
          dataIndex: 'price',
          customCell: (text, record) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('秒杀数量'),
          align: 'center',
          dataIndex: 'seckillNum',
          customCell: (text, record) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('秒杀价'),
          align: 'center',
          dataIndex: 'seckillPrice',
          customCell: (text, record) => {
            return {
              style: {
                textAlign: 'right',
              },
            }
          },
        },
        {
          title: this.$t('会员限购数量'),
          align: 'center',
          dataIndex: 'memberLimit',
        },
        {
          title: this.$t('秒杀说明'),
          align: 'center',
          dataIndex: 'descr',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      secDataSource: [],
      weeks: [
        { key: '1', name: this.$t('周一') },
        { key: '2', name: this.$t('周二') },
        { key: '3', name: this.$t('周三') },
        { key: '4', name: this.$t('周四') },
        { key: '5', name: this.$t('周五') },
        { key: '6', name: this.$t('周六') },
        { key: '7', name: this.$t('周日') },
      ],
      excludeTimeList: [],
      periodList: [],
      weekList: [],
      isAdd: false,
      beginTime: '',
      endTime: '',

      cjColumns: [
        {
          title: this.$t('序号'),
          dataIndex: 'sort',
          align: 'center',
        },
        {
          title: this.$t('奖品类型'),
          align: 'center',
          dataIndex: 'goodsForm',
          scopedSlots: { customRender: 'goodsForm' },
        },
        {
          title: this.$t('奖品名称'),
          align: 'center',
          dataIndex: 'goodsId',
          scopedSlots: { customRender: 'goodsId' },
        },
        {
          title: this.$t('奖品简称'),
          align: 'center',
          dataIndex: 'shortName',
          scopedSlots: { customRender: 'shortName' },
        },
        {
          title: this.$t('数量'),
          align: 'center',
          dataIndex: 'amount',
          scopedSlots: { customRender: 'amount' },
        },
      ],
      cjDataSource: [
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 1 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 2 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 3 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 4 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 5 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 6 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 7 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 8 },
      ],
      isFree: false,
      isConsume: false,
      isDeposit: false,
      freeNum: 1,
      consumeValue: '',
      consumeNum: 1,
      depositValue: '',
      depositNum: 1,
      drawList: [],
      upgradeOrdersList: [],
      recharges: [],
      psColumns: [
        {
          title: this.$t('排序序号'),
          dataIndex: 'sort',
          align: 'center',
          scopedSlots: { customRender: 'sort' },
          customCell: () => {
            return {
              style: {
                width: '80px',
              },
            }
          },
        },
        {
          title: this.$t('商品名称'),
          align: 'center',
          dataIndex: 'goodsId_dictText',
        },
        {
          title: this.$t('商品原价'),
          align: 'center',
          dataIndex: 'originalPrice',
        },
        {
          title: this.$t('预售价格'),
          align: 'center',
          dataIndex: 'presalePrice',
        },
        {
          title: this.$t('定金金额'),
          align: 'center',
          dataIndex: 'deposit',
        },
        {
          title: this.$t('尾款金额'),
          align: 'center',
          dataIndex: 'finalPay',
        },
        {
          title: this.$t('数量'),
          align: 'center',
          dataIndex: 'quantity',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      psDataSource: [],
    }
  },
  methods: {
    changeForm(e, i) {
      if (e != 0) {
        this.handleSearch('', i)
        this.$set(this.cjDataSource[i], 'goodsId', '')
        this.$set(this.cjDataSource[i], 'shortName', '')
      } else {
        this.$set(this.cjDataSource[i], 'goodsId', '')
        this.$set(this.cjDataSource[i], 'shortName', this.$t('谢谢参与'))
      }
    },
    handleSearch(e, i, id) {
      let query = {}
      if (id) {
        query.id = id
      } else {
        query.form = this.cjDataSource[i].goodsForm
        query.goodsInfo = e
      }
      getAction('/goods/bisGoodsInfor/list', query).then((res) => {
        if (res.success) {
          this.$set(this.cjDataSource[i], 'goodsList', res.result.records)
        } else {
          this.$set(this.cjDataSource[i], 'goodsList', [])
        }
      })
    },
    hangeleChange() {},
    setLongTime() {
      this.$set(this.model, 'beginTime', moment().format('YYYY-MM-DD 00:00:00'))
      this.$set(this.model, 'endTime', moment().add(100, 'years').format('YYYY-12-31 23:59:59'))
      this.$refs.form.validateField('beginTime')
      this.$refs.form.validateField('endTime')
    },
    add(value) {
      this.acvivityType = value
      this.visible = true
      this.model = {
        state: 1,
        weeks: ['1', '2', '3', '4', '5', '6', '7'],
      }
      this.model.type = value
      this.edit(this.model)
    },
    async edit(record, state) {
      let that = this
      that.disabled = state
      that.acvivityType = record.type
      if (that.acvivityType == '4') {
        await that.getRecharges()
      }
      that.weekList = []
      that.upgradeOrdersList = []
      that.ruleList = []
      that.excludeTimeList = []
      that.periodList = []
      that.goodSortList = []
      that.model = Object.assign({}, record)
      that.model.state = JSON.stringify(that.model.state)
      that.dataSource = []
      that.secDataSource = []
      that.cjDataSource = [
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 1 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 2 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 3 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 4 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 5 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 6 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 7 },
        { goodsForm: '', goodsList: [], goodsId: '', shortName: '', amount: '1', sort: 8 },
      ]
      that.drawList = []
      that.isFree = false
      that.freeNum = 1
      that.isConsume = false
      that.consumeNum = 1
      that.consumeValue = ''
      that.isDeposit = false
      that.depositNum = 1
      that.depositValue = ''
      that.psDataSource = []
      that.visible = true
      that.$nextTick(() => {
        that.$refs.form.clearValidate()
      })
      initDictOptions('bis_activity.state').then((res) => {
        if (res.success) {
          that.stateList = res.result
        }
      })
      if (that.model.id) {
        getAction('/activity/bisActivity/queryBisActivityWeekByMainId', { id: that.model.id }).then((res) => {
          if (res.success) {
            that.weekList = res.result
            let arr = res.result.map((r) => {
              return '' + r.week
            })
            that.$set(that.model, 'weeks', arr)
          }
        })
        if (that.acvivityType == '0') {
          getAction('/activity/bisActivity/queryBisActivityDiscountByMainId', { id: this.model.id }).then((res) => {
            if (res.success) {
              that.dataSource = res.result
            }
          })
          getAction('/activity/bisActivity/queryBisActivityExcludeTimeByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.excludeTimeList = res.result
              that.excludeTimeList.forEach((col) => {
                that.$set(col, 'disabled', true)
              })
              if (!that.disabled && that.excludeTimeList.length == 0) {
                if (that.excludeTimeList.length == 0) {
                  let aa = {}
                  aa.beginTime = ''
                  aa.endTime = ''
                  aa.disabled = false
                  that.excludeTimeList.push(aa)
                }
              }
            }
          })
          getAction('/activity/bisActivityPeriod/list', { activityId: that.model.id, pageSize: 99 }).then((res) => {
            if (res.success) {
              that.periodList = res.result.records
            }
          })
        }
        if (that.acvivityType == '1') {
          getAction('/activity/bisActivity/queryBisActivityFullByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.ruleList = res.result
              that.ruleList.forEach((col) => {
                that.$set(col, 'disabled', true)
              })
              if (!that.disabled && that.ruleList.length == 0) {
                if (that.ruleList.length == 0) {
                  let aa = {}
                  aa.full = ''
                  aa.discount = ''
                  aa.disabled = false
                  that.ruleList.push(aa)
                }
              }
            }
          })
          getAction('/activity/bisActivity/queryBisActivityFullKindByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.goodSortList = res.result
            }
          })
        }
        if (that.acvivityType == '2') {
          getAction('/activity/bisActivity/queryBisActivitySeckillByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.secDataSource = res.result
            }
          })
        }
        if (that.acvivityType == '3') {
          getAction('/activity/bisActivity/getDetailById', { id: that.model.id }).then((res) => {
            if (res.success) {
              let drawGoodsList = res.result.records[0].drawGoodsList
              drawGoodsList.forEach((d, i) => {
                d.goodsList = [
                  {
                    id: d.goodsId,
                    name: d.goodsId_dictText,
                  },
                ]
              })
              let drawList = res.result.records[0].drawList
              that.cjDataSource = drawGoodsList
              that.drawList = drawList
              that.$nextTick(() => {
                that.isFree = drawList[0].state ? true : false
                that.freeNum = drawList[0].num
                that.isConsume = drawList[1].state ? true : false
                that.consumeNum = drawList[1].num
                that.consumeValue = drawList[1].value
                that.isDeposit = drawList[2].state ? true : false
                that.depositNum = drawList[2].num
                that.depositValue = drawList[2].value
              })
            }
          })
        }
        if (that.acvivityType == '4') {
          getAction('/activity/bisActivity/queryBisActivityUploadOrdersByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.upgradeOrdersList = res.result
              that.upgradeOrdersList.forEach((col) => {
                that.$set(col, 'disabled', false)
                let obj = that.recharges.filter((a) => {
                  return a.id == col.originalGoodsId
                })[0]
                let arr = that.recharges.filter((a) => {
                  return a.form == obj.form && a.id != col.originalGoodsId
                })
                that.$set(col, 'recharges', arr)
              })
              if (!that.disabled && that.upgradeOrdersList.length == 0) {
                let aa = {}
                aa.originalGoodsId = ''
                aa.recommendedGoodsId = ''
                aa.disabled = true
                aa.recharges = []
                that.upgradeOrdersList.push(aa)
              }
            }
          })
        }
        if (that.acvivityType == '5') {
          getAction('/activity/bisActivity/queryBisActivityPresaleByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.$set(that.model, 'depositBegin', res.result.depositBegin)
              that.$set(that.model, 'depositEnd', res.result.depositEnd)
              that.$set(that.model, 'finalBegin', res.result.finalBegin)
              that.$set(that.model, 'finalEnd', res.result.finalEnd)
              that.$set(that.model, 'memberLimit', res.result.memberLimit)
              that.$set(that.model, 'presaleRuleId', res.result.presaleRuleId)
            }
          })
          getAction('/activity/bisActivity/queryBisActivityPresaleGoodsByMainId', { id: that.model.id }).then((res) => {
            if (res.success) {
              that.psDataSource = res.result
            }
          })
        }
      } else {
        if (!that.disabled) {
          let aa = {}
          if (that.acvivityType == '0' && that.excludeTimeList.length == 0) {
            aa.beginTime = ''
            aa.endTime = ''
            aa.disabled = false
            that.excludeTimeList.push(aa)
          }
          if (that.acvivityType == '1' && that.ruleList.length == 0) {
            aa.full = ''
            aa.discount = ''
            aa.disabled = false
            that.ruleList.push(aa)
          }
          if (that.acvivityType == '4' && that.upgradeOrdersList.length == 0) {
            aa.originalGoodsId = ''
            aa.recommendedGoodsId = ''
            aa.disabled = true
            aa.recharges = []
            that.upgradeOrdersList.push(aa)
          }
        }
      }
    },
    editTime(item) {
      this.$set(item, 'disabled', false)
    },
    saveTime(item) {
      let i = 0
      if (item.beginTime > item.endTime) {
        this.$message.warning(this.$t('排除日期-结束日期应晚于开始日期'))
        return
      }
      this.excludeTimeList.forEach((col) => {
        if (col.beginTime != item.beginTime && col.endTime != item.endTime) {
          i++
        } else {
          i--
        }
      })
      if (i == this.excludeTimeList.length - 2) {
        this.$set(item, 'disabled', true)
      } else {
        this.$message.warning(this.$t('已存在重复的排除日期'))
      }
    },
    addTime() {
      let obj = {}
      obj.beginTime = ''
      obj.endTime = ''
      obj.disabled = false
      this.excludeTimeList.push(obj)
    },
    delTime(item) {
      this.excludeTimeList.forEach((col) => {
        if (col.beginTime == item.beginTime && col.endTime == item.endTime) {
          let index = this.excludeTimeList.indexOf(item)
          this.excludeTimeList.splice(index, 1)
        }
      })
      if (this.excludeTimeList.length == 0) {
        let obj = {}
        obj.beginTime = ''
        obj.endTime = ''
        obj.disabled = false
        this.excludeTimeList.push(obj)
      }
    },
    editRule(item) {
      this.$set(item, 'disabled', false)
    },
    saveRule(item) {
      let i = 0
      this.ruleList.forEach((col) => {
        if (
          (col.full == item.full && col.discount == item.discount) ||
          col.full == item.full ||
          col.discount == item.discount
        ) {
          i--
        } else {
          i++
        }
      })
      if (i == this.ruleList.length - 2) {
        this.$set(item, 'disabled', true)
      } else {
        this.$message.warning(this.$t('已存在重复的满减规则'))
      }
    },
    addRule() {
      let obj = {}
      obj.full = ''
      obj.discount = ''
      obj.disabled = false
      this.ruleList.push(obj)
    },
    delRule(item) {
      if (this.ruleList.length == 1) {
        this.$message.warning(this.$t('至少设置一条满减规则'))
        return
      } else {
        this.ruleList.forEach((col) => {
          if (col.full == item.full && col.discount == item.discount) {
            let index = this.ruleList.indexOf(item)
            this.ruleList.splice(index, 1)
          }
        })
      }
    },
    delKind(record) {
      this.dataSource.forEach((item) => {
        if (item.kindId == record.kindId) {
          let index = this.dataSource.indexOf(item)
          this.dataSource.splice(index, 1)
        }
      })
    },
    addGoods() {
      this.$refs.kindForm.edit()
    },
    delDelGoods(item) {
      this.goodSortList.forEach((col) => {
        if (col.kindId == item.kindId) {
          let index = this.goodSortList.indexOf(col)
          this.goodSortList.splice(index, 1)
        }
      })
    },
    addKindCallback(kindid) {
      getAction('/goods/bisGoodsKind/childList', { id: kindid }).then((res) => {
        if (res.success) {
          let aa = {}
          aa.kindName = res.result.records[0].name
          aa.kindId = res.result.records[0].id
          this.goodSortList.push(aa)
        }
      })
    },
    //秒杀
    addSeckill() {
      this.$refs.seckillForm.add()
    },
    addSeckillGoods(dataForm) {
      let i = 0
      if (this.secDataSource.length == 0) {
        this.secDataSource.push(dataForm)
      } else {
        this.secDataSource.forEach((item) => {
          if (item.goodsId == dataForm.goodsId) {
            this.$message.warning(this.$t('已存在') + '“' + item.goodsName + '”' + this.$t('商品'))
          } else {
            i++
          }
        })
        if (i == this.secDataSource.length) {
          this.secDataSource.push(dataForm)
        }
      }
    },
    saveSeckill(id) {
      let that = this
      const target = that.secDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        this.$set(target, 'editable', false)
      }
    },
    editSeckill(id) {
      let that = this
      const target = that.secDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        this.$set(target, 'editable', true)
      }
    },
    handleChange(value, id, column) {
      let that = this
      const target = that.secDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        target[column] = value
      }
    },
    delSeckill(record) {
      this.secDataSource.forEach((item) => {
        if (item.goodsId == record.goodsId) {
          let index = this.secDataSource.indexOf(item)
          this.secDataSource.splice(index, 1)
        }
      })
    },
    //折扣
    handleOkDiscount() {
      if (this.dis.discount == undefined) {
        this.$message.warning(this.$t('折扣不能为空'))
        return
      }
      getAction('/goods/bisGoodsKind/childList', { id: this.dis.kindId }).then((res) => {
        if (res.success) {
          if (this.dis.kindId == '') {
            this.dis.kindName = this.$t('全部')
          } else {
            this.dis.kindName = res.result.records[0].name
          }
          let i = 0
          if (this.dataSource.length == 0) {
            this.dataSource.push(this.dis)
          } else {
            this.dataSource.forEach((item) => {
              if (item.kindId == this.dis.kindId) {
                this.$message.warning(this.$t('已存在') + '“' + this.dis.kindName + '”' + this.$t('分类的折扣'))
              } else {
                i++
              }
            })
            if (i == this.dataSource.length) {
              this.dataSource.push(this.dis)
            }
          }
        }
      })
      this.discountVisible = false
    },
    handleOk() {
      let that = this
      that.$refs.form.validate((valid) => {
        console.log(valid)
        if (valid) {
          let ruleList = [], excludeTimeList = []
          if (moment(that.model.beginTime) >= moment(that.model.endTime)) {
            that.$message.warning(that.$t('结束日期应晚于开始日期'))
            return
          }
          if (that.model.weeks.length == 0) {
            that.$message.warning(that.$t('至少选择一个有效日'))
            return
          }
          let arr = that.model.weeks.map((w) => {
            let dtl = {
              week: w,
            }
            let obj = that.weekList.find((wl) => {
              return wl.week == w
            })
            if (obj) {
              dtl = Object.assign({}, dtl, obj)
            }
            return dtl
          })
          that.model.weekList = arr
          if (that.acvivityType == '0') {
            if (that.dataSource.length == 0) {
              that.$message.warning(that.$t('请添加商品折扣'))
              return
            }
            that.excludeTimeList.forEach((col) => {
              if (col.disabled) {
                let dtl = Object.assign({}, col)
                dtl.beginTime = moment(dtl.beginTime).format('YYYY-MM-DD 00:00:00')
                dtl.endTime = moment(dtl.endTime).format('YYYY-MM-DD 23:59:59')
                delete dtl.disabled
                excludeTimeList.push(dtl)
              }
            })
          }
          if (that.acvivityType == '1') {
            let i = 0
            that.ruleList.forEach((col) => {
              if (col.disabled) {
                ruleList.push(col)
              } else {
                i++
              }
            })
            if (i != 0) {
              that.$message.warning(that.$t('请添加满减规则'))
              return
            }
            if (that.goodSortList.length == 0) {
              that.$message.warning(that.$t('请添加适用商品分类'))
              return
            }
          }
          if (that.acvivityType == '2' && that.secDataSource.length == 0) {
            that.$message.warning(that.$t('请设置秒杀品'))
            return
          }
          if (that.acvivityType == '3') {
            let x = that.cjDataSource.findIndex((ds) => {
              return (
                ds.goodsForm === '' ||
                (ds.goodsForm !== '0' && ds.goodsForm !== 0 && (ds.goodsId == '' || ds.shortName == '' || ds.num == ''))
              )
            })
            if (x > -1) {
              that.$message.warning(that.$t('请设置奖品'))
              return
            }
            if (!that.isFree && !that.isConsume && !that.isDeposit) {
              that.$message.warning(that.$t('请设置抽奖方式'))
              return
            }
            if (
              (that.isFree && !that.freeNum) ||
              (that.isConsume && (!that.consumeNum || !that.consumeValue)) ||
              (that.isDeposit && (!that.depositNum || !that.depositValue))
            ) {
              that.$message.warning(that.$t('请设置抽奖方式'))
              return
            }
          }
          let upgradeOrdersList = that.upgradeOrdersList.filter((a) => {
            return a.originalGoodsId && a.recommendedGoodsId
          })
          if (that.acvivityType == '4' && upgradeOrdersList.length == 0) {
            that.$message.warning(that.$t('请设置升单规则'))
            return
          }
          if (that.acvivityType == '5' && that.psDataSource.length == 0) {
            that.$message.warning(that.$t('请设置预售商品'))
            return
          }
          let query = {}
          query = that.model
          if (that.acvivityType == '0') {
            query.bisActivityDiscountList = that.dataSource
            if (excludeTimeList.length > 0) {
              query.excludeTimeList = excludeTimeList
            }
            query.periodList = that.periodList
          }
          if (that.acvivityType == '1') {
            query.bisActivityFullList = ruleList
            query.bisActivityFullKindList = that.goodSortList
          }
          if (that.acvivityType == '2') {
            query.bisActivitySeckillList = that.secDataSource
          }
          if (that.acvivityType == '3') {
            query.drawGoodsList = that.cjDataSource.map((ds) => {
              let dtl = Object.assign({}, ds)
              delete dtl.goodsList
              return dtl
            })
            if (that.drawList.length > 0) {
              that.drawList[0].state = that.isFree ? 1 : 0
              that.drawList[0].num = that.freeNum
              that.drawList[1].state = that.isConsume ? 1 : 0
              that.drawList[1].num = that.consumeNum
              that.drawList[1].value = that.consumeValue
              that.drawList[2].state = that.isDeposit ? 1 : 0
              that.drawList[2].num = that.depositNum
              that.drawList[2].value = that.depositValue
              query.drawList = that.drawList
            } else {
              query.drawList = [
                {
                  getType: 0,
                  state: that.isFree ? 1 : 0,
                  value: '',
                  num: that.freeNum,
                },
                {
                  getType: 1,
                  state: that.isConsume ? 1 : 0,
                  value: that.consumeValue,
                  num: that.consumeNum,
                },
                {
                  getType: 2,
                  state: that.isDeposit ? 1 : 0,
                  value: that.depositValue,
                  num: that.depositNum,
                },
              ]
            }
          }
          if (that.acvivityType == '4') {
            query.upgradeOrdersList = upgradeOrdersList
          }
          if (that.acvivityType == '5') {
            query.presale = {}
            /* if(that.model.presaleRuleId){
              query.presale.id = that.model.presaleRuleId
            } */
            query.presale.depositBegin = that.model.depositBegin
            query.presale.depositEnd = that.model.depositEnd
            query.presale.finalBegin = that.model.finalBegin
            query.presale.finalEnd = that.model.finalEnd
            query.presale.memberLimit = that.model.memberLimit
            query.presaleGoodsList = that.psDataSource
          }
          that.confirmLoading = true
          let url = ''
          let method = ''
          if (that.model.id) {
            url = '/activity/bisActivity/edit'
            method = 'put'
          } else {
            url = '/activity/bisActivity/add'
            method = 'post'
          }
          httpAction(url, query, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.close()
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    modalFormOk() {
      this.close()
      this.$emit('ok')
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
    addDiscount() {
      this.discountVisible = true
      this.dis = {
        kindId: '',
        discount: undefined,
      }
      this.select()
    },
    handleClose() {
      this.discountVisible = false
    },
    select() {
      let that = this
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.column = 'sort'
      param.order = 'asc'
      getAction('/goods/bisGoodsKind/rootList', param).then((res) => {
        if (res.success) {
          that.allChildKind = []
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.id = '' + col.id
              col.pid = '' + col.pid
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            that.treeData = that.getDataByResult(res.result.records)
            that.treeData.unshift({ key: '', id: '', value: '', title: this.$t('全部') })
          } else {
            that.treeData = []
          }
        } else {
          that.$alert(res.message, this.$t('提示'), {
            confirmButtonText: this.$t('确定'),
            callback: (action) => {},
          })
        }
      })
    },
    getHasChild(record) {
      let that = this
      let query = {}
      query.pageNo = 1
      query.pageSize = 9999
      query.pid = record.id
      getAction('/goods/bisGoodsKind/rootList', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.pid = '' + col.pid
              col.id = '' + col.id
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            record.children = that.getDataByResult(res.result.records)
            that.treeData = [...that.treeData]
          }
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    getDataByResult(result) {
      let that = this
      return result.map((item) => {
        if (item.hasChild == 0 && item.key != '0') {
          that.allChildKind.push(item.key)
        }
        return item
      })
    },
    addValidTime() {
      this.isAdd = !this.isAdd
    },
    delValidTime(ind) {
      this.periodList.splice(ind, 1)
    },
    focusTimeE(bol) {
      if (!bol && !this.beginTime) {
        this.$message.warn('请选择开始时间')
      }
    },
    orgTime(bol) {
      if (!bol) {
        if (!this.beginTime) {
          this.$message.warn('请选择开始时间')
          return
        }
        if (!this.endTime) {
          this.$message.warn('请选择开始时间')
          return
        }
        if (this.beginTime > this.endTime) {
          this.$message.warn('该时间段冲突！')
          return
        }
        this.isAdd = false
        this.periodList.push({
          beginTime: moment(this.beginTime).format('HH:mm'),
          endTime: moment(this.endTime).format('HH:mm'),
        })
        this.beginTime = ''
        this.endTime = ''
      }
    },
    getRecharges() {
      let that = this
      return new Promise((recolve) => {
        let query = {
          pageSize: 9999,
          column: 'sort',
          order: 'asc',
        }
        query.form = '2,14'
        getAction('/goods/bisGoodsInfor/list', query).then((res) => {
          if (res.success) {
            that.recharges = res.result.records
          } else {
            that.recharges = []
          }
          recolve()
        })
      })
    },
    changeRecharge(e, i) {
      let that = this
      let x = that.recharges.findIndex((a) => {
        return a.id == e
      })
      let obj = that.recharges[x]
      let arr = that.recharges.filter((a) => {
        return a.form == obj.form && a.id != e
      })
      let y = that.upgradeOrdersList.filter((a) => {
        return a.originalGoodsId == e
      }).length
      if (y > 1) {
        that.$message.warning(that.$t('原套餐不可重复'))
        that.$set(that.upgradeOrdersList[i], 'originalGoodsId', '')
        return
      }
      that.$set(that.upgradeOrdersList[i], 'recharges', arr)
      that.$set(that.upgradeOrdersList[i], 'disabled', false)
      that.$set(that.upgradeOrdersList[i], 'recommendedGoodsId', '')
    },
    addRecharge() {
      let obj = {}
      obj.originalGoodsId = ''
      obj.recommendedGoodsId = ''
      obj.recharges = []
      obj.disabled = true
      this.upgradeOrdersList.push(obj)
    },
    delRecharge(item) {
      if (this.upgradeOrdersList.length == 1) {
        this.$message.warning(this.$t('请设置升单规则'))
        return
      } else {
        this.upgradeOrdersList.forEach((col, i) => {
          if (col.originalGoodsId == item.originalGoodsId && col.recommendedGoodsId == item.recommendedGoodsId) {
            this.upgradeOrdersList.splice(i, 1)
          }
        })
      }
    },
    addPresale() {
      this.$refs.presaleForm.add()
    },
    addPresaleGoods(dataForm) {
      let i = 0
      if (this.psDataSource.length == 0) {
        this.psDataSource.push(dataForm)
      } else {
        this.psDataSource.forEach((item) => {
          if (item.goodsId == dataForm.goodsId) {
            this.$message.warning(this.$t('已存在') + '“' + item.goodsId_dictText + '”' + this.$t('商品'))
          } else {
            i++
          }
        })
        if (i == this.psDataSource.length) {
          this.psDataSource.push(dataForm)
        }
      }
    },
    savePresale(id){
      let that = this
      const target = that.psDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        this.$set(target, 'editable', false)
      }
    },
    editPresale(id){
      let that = this
      const target = that.psDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        this.$set(target, 'editable', true)
      }
    },
    handleChangePs(value, id, column) {
      let that = this
      const target = that.psDataSource.filter((item) => id === item.goodsId)[0]
      if (target) {
        target[column] = value
      }
    },
    delPresale(record) {
      this.psDataSource.forEach((item) => {
        if (item.goodsId == record.goodsId) {
          let index = this.psDataSource.indexOf(item)
          this.psDataSource.splice(index, 1)
        }
      })
    },
  },
}
</script>
<style>
.batchForm .ant-form-item-label {
  width: 30%;
}
.batchForm .ant-form-item-control-wrapper {
  width: 62.5%;
}
</style>